package com.sss.dao.impl;

import com.sss.dao.CustomerDao;
import com.sss.dao.DBHelper;
import com.sss.entity.Customer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author sss
 * @Date: 2023/10/13/ 15:36
 * @description:
 */
public class CustomerDaoImpl extends DBHelper implements CustomerDao {

    @Override
    public void saveCustomer(Customer customer) {
        //先获取连接
        Connection conn=getConn();
        //然后进行
        String sql="insert into customer.cst_customer( cust_name, cust_source, cust_industry, cust_level, cust_phone, cust_address) values (?,?,?,?,?,?)";
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            ps=conn.prepareStatement(sql);
            //填充占位符
            ps.setString(1,customer.getName());
            ps.setString(2,customer.getSource());
            ps.setString(3,customer.getIndustry());
            ps.setString(4,customer.getLevel());
            ps.setString(5,customer.getPhone());
            ps.setString(6,customer.getAddress());
            ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            closeAll(conn, ps, rs);
        }
    }
}
